<script lang="ts" setup>
import { RoomApi, RoomVO } from '@/api/ecg/room'
import { QueueApi } from '@/api/ecg/queue'
import {PropType} from "vue";
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
import {useCheckTypeStore} from "@/store/modules/checkType";
const emit = defineEmits(['refresh'])

defineComponent({
  name: 'RoomStatus'
})

const  props = defineProps({
  title: {
    type: String,
    required: true
  },
  bedList: {
    type: Array as PropType<RoomVO[]>,
    required: true
  }
})

const checkTypeStore = useCheckTypeStore();

const openBed = async (item) => {
    await QueueApi.bedOpen(item)
    emit('refresh')
}

const closeBed = async (item) => {
    await QueueApi.bedClose(item)
    emit('refresh')
}

/** 初始化 **/
onMounted(() => {
})

</script>

<template>
  <el-card style="width: 200px" shadow="hover" >
    <template #header>{{title}}</template>
    <div v-for="(bedItem, index) in bedList" :key="index">
      <div class="deskwarp">
        <img
            v-if="bedItem.status === 0"
            src="@/assets/room/close.jpg"
            style="width: 100%"
             @click = openBed(bedItem)
            alt="工位已关闭"
        />
        <img
            v-else-if="bedItem.status === 10"
            src="@/assets/room/open.jpg"
            style="width: 100%"
             @click = closeBed(bedItem)
            alt="工位开放中"
        />
        <img v-else-if="bedItem.status === 20 || bedItem.status === 30"
            src="@/assets/room/doctor.png"
            style="width: 100%"
        />
        {{bedItem.bedNo}} {{bedItem.docName}} {{bedItem.status === 30?"-暂停":""}}
        <div v-for="(checkType, subIndex) in bedItem.checkTypes" :key="subIndex">
          {{checkTypeStore.getCheckTypeName(checkType)}}
        </div>
        <div>
          {{bedItem.opType === 1?"领用":""}}
          {{bedItem.opType === 2?"安装":""}}
        </div>
        <el-divider/>
      </div>
    </div>
  </el-card>
</template>

<style scoped lang="scss">
.card-title {
  font-size: 14px;
  font-weight: 600;

  &::before {
    position: relative;
    top: 8px;
    left: -5px;
    display: inline-block;
    width: 3px;
    height: 14px;
    //background-color: #105cfb;
    background: var(--el-color-primary);
    border-radius: 5px;
    content: '';
    transform: translateY(-50%);
  }
}

.deskwarp {
  display: flex;
  flex-direction: column;
  align-items: center;
}

</style>
